//
//  WBNavigationController.swift
//  新浪微博
//
//  Created by 名品导购网MPLife.com on 2017/11/20.
//  Copyright © 2017年 sweet. All rights reserved.
//

import UIKit

class WBNavigationController: UINavigationController {

    override func viewDidLoad() {
        super .viewDidLoad()
        //隐藏默认的navigatorBar 解决导航条融合问题
        navigationBar.isHidden = true
    }
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        //如果不是栈低控制器才需要隐藏 根控制器不需要处理
        //隐藏地步tabbar
        if childViewControllers.count > 0 {
            viewController .hidesBottomBarWhenPushed = true
            //判断控制器的类型
            if let vc = viewController as? WBBaseViewController {
                //取出navItem
                var title = "返回"
                //判断控制器的级数
                if childViewControllers.count == 1{
                    //title显示首页的标题
                    title = childViewControllers.first?.title ?? "返回"
                }

                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, target: self, action: #selector(popToParent),isBack:true)
            }
        }

        super.pushViewController(viewController, animated: true)
    }
    @objc private func popToParent(){
        popViewController(animated: true)
    }
}



